package com.iwhalecloud.bss.kite.cucc.service.spec.query;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Collectors;

import com.iwhalecloud.bss.kite.cucc.common.callclient.HttpsCallClient;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iwhalecloud.bss.hsf.baseinf.service.InfExchangeService;
import com.iwhalecloud.bss.kite.client.api.cust.query.IQueryCustService;
import com.iwhalecloud.bss.kite.client.api.spec.query.IQueryOfferSpecService;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.dto.spec.AttrDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.IntegralOfferDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.ObjectLabelRelDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferAttrDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferDetailDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferEffExpConfigDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferLabelDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferRelDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.OfferRoleExtDTO;
import com.iwhalecloud.bss.kite.client.dto.spec.in.QryOfferInDTO;
import com.iwhalecloud.bss.kite.client.vo.scene.SpeedTypeVO;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.LabelConsts;
import com.iwhalecloud.bss.kite.common.constant.SwitchConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.common.validate.annotation.KiteNotBlank;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalCallClientEnum;
import com.iwhalecloud.bss.kite.cucc.service.inf.InfServiceHelper;
import com.iwhalecloud.bss.kite.cucc.service.util.CallClientUtils;
import com.iwhalecloud.bss.kite.cucc.service.util.LocalTokenUtil;
import com.iwhalecloud.bss.kite.cucc.spec.impl.transfer.GoodsInfoTransfer;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryOfferService;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferDetailCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferDisplayConfigCache;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferLabelCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProdRelCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProductCache;
import com.iwhalecloud.bss.kite.dataservice.cache.QueryOfferCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.dataservice.entity.ObjectLabelRel;
import com.iwhalecloud.bss.kite.dataservice.entity.OfferAttr;
import com.iwhalecloud.bss.kite.dataservice.entity.OfferEffExpConfig;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.OfferDetail;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.OfferDisplayConfig;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.OfferRelInfo;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdAttrValueRestrictInfo;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdRelInfo;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Product;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.OfferDetailMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.OfferMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.OfferRelMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProdAttrValueRestrictInfoMapper;
import com.iwhalecloud.bss.kite.dataservice.util.GeneralSwitchUtils;
import com.iwhalecloud.bss.kite.dataservice.util.OfferRestrictUtil;
import com.iwhalecloud.bss.kite.manager.enums.RelType;
import com.iwhalecloud.bss.kite.service.util.CopyToDtoUtil;

import com.ztesoft.bss.base.staticdata.CoreDataOffer;
import com.ztesoft.bss.base.staticdata.CoreDataProduct;
import com.ztesoft.bss.common.bo.LoginInfo;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.I18nUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import com.ztesoft.bss.order.base.consts.IKeyValues;
import com.ztesoft.bss.order.base.consts.KeyValues;
import com.ztesoft.bss.order.base.consts.KeyValuesLocal;
import com.ztesoft.zsmart.core.util.JsonUtil;

@Service
public class QueryOfferSpecService implements IQueryOfferSpecService {

    @Autowired
    OfferRelMapper offerRelMapper;
    @Autowired
    IQueryCustService queryCustService;
    @Autowired
    OfferDetailMapper offerDetailMapper;
    @Autowired
    private IQueryOfferService queryOfferService;

    @Override
    public DataResult<OfferDTO> getOfferInfo(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = queryOfferService.getOffer(offerId);
        if (offer == null) {
            ErrorConsts.OFFER_NOT_EXISTS.throwOut(offerId);;
        }

        OfferDTO offerDTO = new OfferDTO();
        KiteBeanUtils.copyProperties(offer, offerDTO);
        return ErrorConsts.SUCCESS.getResult(offerDTO);
    }

    @Override
    public DataResult<List<AttrDTO>> listOfferAttrs(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        List<OfferAttr> list = offer.listOfferAttrs();
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(list, AttrDTO.class));
    }


    @Override
    public DataResult<List<OfferAttrDTO>> listOfferAttrs(String offerId, String attrName) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");

        List<OfferAttr> offerAttrList = queryOfferService.listDisplayOfferAttrs(offerId);
        if (CollectionUtils.isNotEmpty(offerAttrList)) {
            if (StringUtils.isNotEmpty(attrName)) {
                Iterator<OfferAttr> iter = offerAttrList.iterator();
                while (iter.hasNext()) {
                    OfferAttr offerAttr = iter.next();
                    if (StringUtils.isEmpty(offerAttr.getAttrName()) || !offerAttr.getAttrName().contains(attrName)) {
                        iter.remove();
                    }
                }
            }
            return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(offerAttrList, OfferAttrDTO.class));
        }
        return ErrorConsts.SUCCESS.getResult(new ArrayList<>());
    }

    @Override
    public DataResult<IntegralOfferDTO> getIntegralOffer(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        // 拿到销售品基本信息
        Offer offer = OfferCache.get(offerId);
        OfferDTO offerDTO = KiteBeanUtils.transform(offer, OfferDTO.class);

        // 拿到销售品属性集合
        List<OfferAttr> attrList = offer.listOfferAttrs();
        List<AttrDTO> attrDTOlist = KiteBeanUtils.copyPropsForList(attrList, AttrDTO.class);

        // 拿到销售品明细成员集合
        List<OfferDetail> offerDetails = offer.listOfferDetails();
        List<OfferDetailDTO> offerDetailList = KiteBeanUtils.copyPropsForList(offerDetails, OfferDetailDTO.class);

        // 拿到销售品可选包集合
        // List<Offer> additionalList = offer.listOfferAdditionals(null);
        // List<OfferDTO> offerAdditionalList = BeanUtils.copyPropsForList(additionalList, OfferDTO.class);
        List<OfferRelInfo> allOfferRelInfos = offer.listAllOfferRels();
        List<OfferRelDTO> allOfferRels = KiteBeanUtils.copyPropsForList(allOfferRelInfos, OfferRelDTO.class);

        // //拿到销售品必选可选包集合
        // List<Offer> mustAdditionalList = offer.listOfferAdditionals("1200");
        // List<OfferDTO> offerMustAdditionalList = BeanUtils.copyPropsForList(mustAdditionalList, OfferDTO.class);
        //
        // //拿到销售品缺省可选包集合
        // List<Offer> defaultAdditionalList = offer.listOfferAdditionals("1300");
        // List<OfferDTO> offerDefaultAdditionalList = BeanUtils.copyPropsForList(defaultAdditionalList,
        // OfferDTO.class);
        // List<OfferRelInfo> offerRelInfos = offer.listAllOfferRels();

        // 返回结果
        IntegralOfferDTO result = new IntegralOfferDTO();
        result.setOfferInfo(offerDTO);
        result.setOfferAttrs(attrDTOlist);
        result.setOfferDetail(offerDetailList);
        result.setOfferAdditional(allOfferRels);
        // result.setOfferMustAdditional(offerMustAdditionalList);
        // result.setOfferDefaultAdditional(offerDefaultAdditionalList);
        return ErrorConsts.SUCCESS.getResult(result);
    }

    @Override
    public DataResult<List<OfferDetailDTO>> listOfferDetails(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listOfferDetails(), OfferDetailDTO.class));
    }

    @Override
    public DataResult<List<OfferEffExpConfigDTO>> listOfferEffExpConfigs(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        List<OfferEffExpConfig> list = offer.listOfferEffExpConfigs();
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(list, OfferEffExpConfigDTO.class));

    }

    @Override
    public DataResult<List<OfferLabelDTO>> listOfferLabels(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        List<ObjectLabelRel> list = offer.listOfferLabels();
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(list, OfferLabelDTO.class));
    }

    @Override
    public DataResult<Boolean> hasOfferLabel(String offerId, String labelId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(labelId, "labelId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS.getResult(offer.getOfferLabelJudge(labelId) > 0);
    }

    @Override
    public DataResult<PageInfo<OfferDTO>> listOffersByOfferName(String offerName, String custId, Integer pageIndex, Integer pageSize) {
        PageInfo<OfferDTO> result = null;
        // 判断不能为null
        KiteObjectUtils.checkParamIsEmpty(offerName, "offerName");

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("content", offerName);
        if (null == pageIndex) {
            pageIndex = KeyConsts.PAGE_NUM_DEFAUT;
        }
        if (null == pageSize) {
            pageSize = KeyConsts.MAX_PAGE_SIZE_DEFAUT;
        }
        result = fetchOfferListOptimization(paramMap, custId, pageIndex, pageSize);

        return ErrorConsts.SUCCESS.getResult(result);
    }

    @Override
    public PageInfo<OfferDTO> listOffersByConditions(QryOfferInDTO queryParam, String custId) {
        PageInfo<OfferDTO> result = null;
        // 参数处理
        Map<String, Object> busiMap = new HashMap<String, Object>();

        busiMap.put("content", queryParam.getOfferName() == null ? "" : queryParam.getOfferName());
        busiMap.put("roleCd", queryParam.getRoleCd() == null ? "" : queryParam.getRoleCd());
        busiMap.put("lowerOfferGrade", queryParam.getLowerOfferGrade() == null ? "" : queryParam.getLowerOfferGrade());
        busiMap.put("upperOfferGrade", queryParam.getUpperOfferGrade() == null ? "" : queryParam.getUpperOfferGrade());
        int pageIndex = KeyConsts.PAGE_NUM_DEFAUT;
        int pageSize = KeyConsts.MAX_PAGE_SIZE_DEFAUT;
        if (null != queryParam.getPageIndex()) {
            pageIndex = queryParam.getPageIndex();
        }
        if (null != queryParam.getPageSize()) {
            pageSize = queryParam.getPageSize();
        }

        result = fetchOfferListOptimization(busiMap, custId, pageIndex, pageSize);

        return result;
    }

    @SuppressWarnings("deprecation")
    @Override
    public PageInfo<OfferDTO> listHotSaleOffers(QryOfferInDTO queryParam) {
        // 参数处理

        int currentPage = KeyConsts.PAGE_NUM_DEFAUT;
        int pageSize = KeyConsts.MAX_PAGE_SIZE_DEFAUT;
        if (queryParam.getPageIndex() != null) {
            currentPage = queryParam.getPageIndex();
        }
        if (queryParam.getPageSize() != null) {
            pageSize = queryParam.getPageSize();
        }
        OfferMapper offerMapper = SpringUtil.getBean(OfferMapper.class);
        // 获取员工登陆信息
        LoginInfo loginInfo = ContextUtil.getLoginInfo();
        String partyRoleId = ContextUtil.getSimpleLoginInfo().getUserId() + "";
        String lan_id = loginInfo.getUserInfo().getPostLanId();
        String prov_id = loginInfo.getUserInfo().getPostProvinceNbr() == null ? KeyConsts.PRIV_CODE
            : loginInfo.getUserInfo().getPostProvinceNbr() + "";
        String region_id = loginInfo.getUserInfo().getPostRegionId() + "";
        String channel_id = loginInfo.getOrgInfo().getChannelId() + "";
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("partyRoleId", partyRoleId);
        paramMap.put("lanId", lan_id);
        paramMap.put("provId", prov_id);
        paramMap.put("regionId", region_id);
        paramMap.put("channelId", channel_id);
        paramMap.put("labelId", KeyValuesLocal.OFFER_CAT_89_TYPE);
        DcPublic dcPublic = DcPublicCache.get("2019062501", "staffOfferPrivSwitch");
        if (Objects.nonNull(dcPublic)) {
            paramMap.put("privSwitch", dcPublic.getCodea());
        }

        PageHelper.startPage(currentPage, pageSize);
        List<OfferDTO> offerdto = offerMapper.fetchHotSale(paramMap);
        // 需要权限过滤
        PageInfo<OfferDTO> pageInfo = new PageInfo<>(offerdto);
        return pageInfo;
    }

    @Override
    public DataResult<List<OfferRelDTO>> listMutexOfferRels(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listMutexOfferRels(), OfferRelDTO.class));
    }

    @Override
    public DataResult<List<OfferRelDTO>> listMutexOfferRels(String offerId, String relType) {
        return null;
    }

    @Override
    public DataResult<Boolean> hasMutexOfferRel(String aOfferId, String zOfferId) {
        KiteObjectUtils.checkParamIsEmpty(aOfferId, "aOfferId");
        KiteObjectUtils.checkParamIsEmpty(zOfferId, "zOfferId");
        Offer offer = OfferCache.get(aOfferId);
        return ErrorConsts.SUCCESS.getResult(offer.getOfferRelJudge(zOfferId) > 0);
    }

    @Override
    public DataResult<List<OfferRelDTO>> listRelyOnOfferRels(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listOfferRelyOns(), OfferRelDTO.class));
    }

    @Override
    public DataResult<List<OfferDTO>> listDefaultAdditionalOffers(String offerId, String prodId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(prodId, "prodId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listDefaultAdditionalOffers(prodId), OfferDTO.class));
    }

    @Override
    public DataResult<List<OfferDTO>> listMustAdditionalOffers(String offerId, String prodId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(prodId, "prodId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listMustAdditionalOffers(prodId), OfferDTO.class));
    }

    @Override
    public DataResult<List<OfferDTO>> listAdditionalOffers(String offerId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        Offer offer = OfferCache.get(offerId);
        List<Offer> offers = new ArrayList<Offer>();
        List<OfferRelInfo> offerRelInfos = offer.listAllOfferRels();
        offerRelInfos.forEach(offerRelInfo -> {
            offers.add(OfferCache.get(offerRelInfo.getzOfferId()));
        });
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(offers, OfferDTO.class));
    }

    // @Override
    // public DataResult<List<OfferRoleDTO>> listAdditionalOfferRoles(String offerId) {
    // if (StringUtil.isEmpty(offerId)) {
    // return ErrorConsts.SYSTEM_ERROR.getResult(null);
    // }
    // Offer offer = OfferCache.get(offerId);
    // return ErrorConsts.SUCCESS.getResult(BeanUtils.copyPropsForList(offer.listOfferAdditionalRoles(),
    // OfferRoleDTO.class));
    // }

    @Override
    public DataResult<List<OfferRelDTO>> listOfferRelsByOfferName(String offerId, String prodId, String offerName) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(prodId, "prodId");
        KiteObjectUtils.checkParamIsEmpty(offerName, "offerName");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils
            .copyPropsForList(offer.listOfferAdditionalsByOfferName(prodId, offerName), OfferRelDTO.class));
    }

    @Override
    public DataResult<List<OfferDTO>> listAdditionalOffersByOfferName(String offerId, String prodId, String roleId,
        String offerName) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(prodId, "prodId");
        // KiteObjectUtils.checkParamIsEmpty(roleId, "roleId");
        KiteObjectUtils.checkParamIsEmpty(offerName, "offerName");

        Offer offer = OfferCache.get(offerId);
        if (KiteStringUtils.isEmpty(roleId)) {
            return ErrorConsts.SUCCESS.getResult(KiteBeanUtils
                .copyPropsForList(offer.getProdAdditionalOffersByOfferName(prodId, offerName), OfferDTO.class));
        }
        else {
            return ErrorConsts.SUCCESS.getResult(KiteBeanUtils
                .copyPropsForList(offer.getOfferRelsByOfferName(roleId, prodId, offerName), OfferDTO.class));
        }

    }

    @Override
    public DataResult<List<OfferDTO>> listAllAdditionalOffersByOfferName(String offerId, String prodId, String roleId,
        String offerName, String custId, String sceneInstId) {
        List<OfferDTO> offers = new ArrayList<>();
        Offer offer = OfferCache.get(offerId);
        if (null == offer) {
            ErrorConsts.OFFER_NOT_EXISTS.throwOut(offerId);
        }

        if (KeyConsts.OFFER_TYPE_15.equals(offer.getOfferType())) {
            // 礼包查询
            List<OfferDetail> offerDetailList = OfferDetailCache.listGiftOfferDetails(offerId);
            offerDetailList.forEach(offerDetail -> {
                Offer offerChild = OfferCache.get(offerDetail.getObjId());
                if (CoreDataOffer.OFF_0005_11.equals(offerChild.getOfferType())
                    || CoreDataOffer.OFF_0005_13.equals(offerChild.getOfferType())) {
                    // 处理促销和套餐销售品
                    offers.addAll(listAllAdditionalOffersByOfferName(offerDetail.getObjId(), prodId, roleId, offerName,
                        custId, sceneInstId).getResultObject());
                }
            });
        }
        else {

            final String type = CoreDataOffer.OFF_0005_10.equals(offer.getOfferType())
                ? KeyConsts.ADDITIONAL_PRODUCT_TYPE
                : KeyConsts.ADDITIONAL_OFFER_TYPE;

            // 套餐销售品
            List<OfferDTO> offerList = this.listAdditionalOffersByOfferName(offerId, prodId, roleId, offerName)
                .getResultObject();
            setType(offerList, type);
            // 基础销售品
            Product product = ProductCache.get(prodId);
            if (null == product) {
                ErrorConsts.PRODUCT_NOT_EXISTS.throwOut(prodId);
            }
            String baseOfferId = product.getBaseOfferId();
            if (!KiteStringUtils.equals(offerId, baseOfferId)) {
                List<OfferDTO> productOffer = this.listAdditionalOffersByOfferName(baseOfferId, prodId, null, offerName)
                    .getResultObject();
                setType(productOffer, KeyConsts.ADDITIONAL_PRODUCT_TYPE);
                this.distinctOfferByOfferId(offerList, productOffer);
                offerList.addAll(productOffer);
            }
            offers.addAll(offerList);
        }

        // 过滤
        return ErrorConsts.SUCCESS.getResult(KiteListUtils.distinctByPropertyName(offers, "offerId"));
    }

    /**
     * 区分是销售品还是产品约束出来的
     *
     * @param offerList
     * @param type
     */
    private void setType(List<OfferDTO> offerList, String type) {
        offerList.forEach(offerDTO -> {
            offerDTO.setType(type);
        });
    }

    // @Override
    // public DataResult<List<OfferDTO>> listAdditionalOffersByRoleId(String offerId, String roleId) {
    // if (StringUtil.isEmpty(offerId) || StringUtil.isEmpty(roleId)) {
    // return ErrorConsts.SYSTEM_ERROR.getResult(null);
    // }
    // Offer offer = OfferCache.get(offerId);
    // return ErrorConsts.SUCCESS.getResult(BeanUtils.copyPropsForList(offer.listOfferAdditionalsByRoleId(roleId),
    // OfferDTO.class));
    // }

    /**
     * Description: <br>
     *
     * @author tengg<br>
     * @taskId <br>
     * @param queryParam
     * @return <br>
     */
    @SuppressWarnings("deprecation")
    @Override
    public PageInfo<OfferDTO> listFavoritesOffers(QryOfferInDTO queryParam) {
        OfferMapper offerMapper = SpringUtil.getBean(OfferMapper.class);
        // 获取员工登陆信息
        LoginInfo loginInfo = ContextUtil.getLoginInfo();
        String partyRoleId = ContextUtil.getSimpleLoginInfo().getUserId() + "";
        String lan_id = loginInfo.getUserInfo().getPostLanId();
        String prov_id = loginInfo.getUserInfo().getPostProvinceNbr() == null ? KeyConsts.PRIV_CODE
            : loginInfo.getUserInfo().getPostProvinceNbr() + "";
        String region_id = loginInfo.getUserInfo().getPostRegionId() + "";
        String channel_id = loginInfo.getOrgInfo().getChannelId() + "";
        String orgId = KiteStringUtils.valueOf(loginInfo.getOrgInfo().getOrgId());
        String staffCode = loginInfo.getUserInfo().getUserCode();
        String specializedChannel = OfferRestrictUtil.getSpecializedChannel(loginInfo);

        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("partyRoleId", partyRoleId);
        paramMap.put("lanId", lan_id);
        paramMap.put("provId", prov_id);
        paramMap.put("regionId", region_id);
        paramMap.put("channelId", channel_id);
        paramMap.put("labelId", KeyValuesLocal.OFFER_CAT_89_TYPE);
        paramMap.put("collectionType", "C");
        paramMap.put("orgId", orgId);
        paramMap.put("staffId", partyRoleId);
        paramMap.put("staffCode", staffCode);
        paramMap.put("specializedChannel", specializedChannel);

        if (null != queryParam.getOfferName() && KiteStringUtils.isNotEmpty(queryParam.getOfferName())) {
            paramMap.put("offerName", "%" + queryParam.getOfferName() + "%");
        }
        int currentPage = KeyConsts.PAGE_NUM_DEFAUT;
        int pageSize = KeyConsts.MAX_PAGE_SIZE_DEFAUT;
        if (null != queryParam.getPageIndex()) {
            currentPage = queryParam.getPageIndex();
        }
        if (null != queryParam.getPageSize()) {
            pageSize = queryParam.getPageSize();
        }
        PageHelper.startPage(currentPage, pageSize);
        List<OfferDTO> offerdto = offerMapper.fetchFavOffer(paramMap);
        // 需要权限过滤
        PageInfo<OfferDTO> pageInfo = new PageInfo<>(offerdto);
        marking(offerdto);
        pageInfo.setTotal(offerdto.size());
        return pageInfo;
    }

    /**
     * Description: <br>
     *
     * @author tengg<br>
     * @taskId <br>
     * @param queryParam
     * @return <br>
     */
    @Override
    public PageInfo<OfferDTO> listCommonOffers(QryOfferInDTO queryParam) {
        PageInfo<OfferDTO> result = null;
        // 参数处理
        Map<String, Object> busiMap = new HashMap<String, Object>();

        busiMap.put("roleCd", queryParam.getRoleCd() == null ? "" : queryParam.getRoleCd());
        // 推荐、常用
        busiMap.put("comLabelId", KeyConsts.LABEL_ID_10000);
        busiMap.put("recomLabelId", KeyConsts.LABEL_ID_10001);
        int pageIndex = KeyConsts.PAGE_NUM_DEFAUT;
        int pageSize = KeyConsts.MAX_PAGE_SIZE_DEFAUT;
        if (null != queryParam.getPageIndex()) {
            pageIndex = queryParam.getPageIndex();
        }
        if (null != queryParam.getPageSize()) {
            pageSize = queryParam.getPageSize();
        }
        result = fetchOfferListOptimization(busiMap, "", pageIndex, pageSize);
        return result;
    }

    /***
     * 根据销售品下某个成员的必选促销
     *
     * @param offerId
     * @param prodId
     * @return
     */
    @Override
    public DataResult<List<OfferDTO>> listMustPromotionOffers(String offerId, String prodId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(prodId, "prodId");
        Offer offer = OfferCache.get(offerId);
        return ErrorConsts.SUCCESS
            .getResult(KiteBeanUtils.copyPropsForList(offer.listMustPromotionOffers(prodId), OfferDTO.class));
    }

    @SuppressWarnings("deprecation")
    private PageInfo<OfferDTO> fetchOfferListOptimization(Map<String, Object> paramMap, String custId, int currentPage, int pageSize) {
        // 获取员工登陆信息
        LoginInfo loginInfo = ContextUtil.getLoginInfo();
        String partyRoleId = KiteStringUtils.valueOf(loginInfo.getUserInfo().getUserId());
        String lan_id = loginInfo.getUserInfo().getPostLanId();
        String prov_id = KiteStringUtils.defaultIfEmpty(loginInfo.getUserInfo().getPostProvinceNbr(), KeyConsts.PRIV_CODE);
        String region_id = KiteStringUtils.valueOf(loginInfo.getUserInfo().getPostRegionId());
        String channel_id = KiteStringUtils.valueOf(loginInfo.getOrgInfo().getChannelId());
        String orgId = KiteStringUtils.valueOf(loginInfo.getOrgInfo().getOrgId());
        String staffCode = loginInfo.getUserInfo().getUserCode();
        String specializedChannel = OfferRestrictUtil.getSpecializedChannel(loginInfo);

        paramMap.put("partyRoleId", partyRoleId);
        paramMap.put("lanId", lan_id);
        paramMap.put("provId", prov_id);
        paramMap.put("regionId", region_id);
        paramMap.put("channelId", channel_id);
        paramMap.put("orgId", orgId);
        paramMap.put("staffId", partyRoleId);
        paramMap.put("staffCode", staffCode);
        paramMap.put("specializedChannel", specializedChannel);
        if (null != paramMap.get("content") && KiteStringUtils.isNotEmpty(String.valueOf(paramMap.get("content")))) {
            paramMap.put("offerName", "%" + paramMap.get("content") + "%");
        }
        DcPublic dcPublic = DcPublicCache.get("2019062501", "staffOfferPrivSwitch");
        if (Objects.nonNull(dcPublic)) {
            paramMap.put("privSwitch", dcPublic.getCodea());
        }
        List<OfferDTO> offerdto = fetchOfferListOptimization(paramMap, currentPage, pageSize);
        Iterator<OfferDTO> iter = offerdto.iterator();
        //FIXME roleCd == '70000999' 这个取值不知是 谁 定义的，遍观代码后发现此值是用于区分是否查询列表时只返回礼包的数据。。。很无奈，在发现这种特值的时候，已经有很多地方在调用此通用查询
        if (paramMap.get("roleCd").equals("70000999")) {
            while (iter.hasNext()) {
                boolean flag = false;
                OfferDTO offerObj = iter.next();
                List<OfferDetail> offerDetailList = OfferDetailCache.listGiftOfferDetails(offerObj.getOfferId());
                for (OfferDetail offerDetail: offerDetailList) {
                    Offer offer = OfferCache.get(offerDetail.getObjId());
                    //筛选掉有失效成员的礼包
                    if (Objects.isNull(offer) || Objects.isNull(offer.getEffDate()) || Objects.isNull(offer.getExpDate())
                        || LocalDateTime.now().isBefore(offer.getEffDate()) || LocalDateTime.now().isAfter(offer.getExpDate())
                        || !KiteStringUtils.equals(KeyValues.STATUS_CD_1000, offer.getStatusCd())) {
                        iter.remove();
                        flag = true;
                        break;
                    }
                }

                if (!flag) {
                    //List<Map<String, Object>> labelList = objectLabelRelMapper.listLabel(iter.next().getOfferId());
                    List<ObjectLabelRel> labelList = OfferLabelCache.get(offerObj.getOfferId());
                    if (CollectionUtils.isNotEmpty(labelList)) {
                        List<ObjectLabelRelDTO> labelRelDtoList = labelList.stream().map(t -> KiteBeanUtils.transform(t, new ObjectLabelRelDTO()))
                            .collect(Collectors.toList());
                        offerObj.setObjLabelRelList(labelRelDtoList);
                    }
                }

            }
        }
        marking(offerdto);
        sorting(offerdto);
        PageInfo<OfferDTO> pageInfo = new PageInfo<>(offerdto);
        return pageInfo;
    }

    private void marking(List<OfferDTO> offerDTOs) {
        offerDTOs.forEach(t -> {
            if (KeyConsts.OFFER_TYPE_13.equals(t.getOfferType()) && KeyConsts.OFFER_SYS_TYPE_1599.equals(t.getOfferSysType())) {
                t.setContractOfferFlag(KeyConsts.IFTRUE_T);
            }
        });
    }

    private void sorting(List<OfferDTO> offerDTOs) {
        if (GeneralSwitchUtils.isSwitchOpened(SwitchConsts.OFFER_DISPLAY_SORTING)) {
            String lanId = ContextUtil.getLandId();
            offerDTOs.sort(Comparator.comparing(t -> OfferDisplayConfigCache.get(t.getOfferId(), lanId).map(OfferDisplayConfig::getOrderBy).orElse(Integer.MAX_VALUE)));
        }
    }

    /***
     * 根据销售品ID查询礼包销售品产品成员
     *
     * @param offerId
     * @return
     */
    @Override
    public DataResult<List<OfferDetailDTO>> listGiftOfferProdDetails(@KiteNotBlank String offerId) {
        Offer offer = OfferCache.get(offerId);
        // 默认返回销售品明细
        List<OfferDetail> offerDetails = offer.listOfferDetails();
        if (KiteStringUtils.equals(offer.getOfferType(), KeyConsts.OFFER_TYPE_15)) {
            // 产品ID+角色ID作为key，存放明细
            Map<String, OfferDetail> offerDetailMap = new HashMap<>();
            // 获取套餐级成员
            List<OfferDetail> prodOfferDetails = offer.listOfferDetailsByObjType(CoreDataOffer.OFF_C_0044_110000);
            if (KiteListUtils.isEmpty(prodOfferDetails)) {
                return ErrorConsts.SUCCESS
                    .getResult(KiteBeanUtils.copyPropsForList(offerDetails, OfferDetailDTO.class));
            }

            prodOfferDetails.forEach(curOfferDetail -> {
                Offer detailOffer = OfferCache.get(curOfferDetail.getObjId());
                if (Objects.isNull(detailOffer)) {
                    return;
                }

                Optional.ofNullable(detailOffer.listOfferDetailsByObjType(CoreDataOffer.OFF_C_0044_100000))
                    .map(details -> {
                        details.forEach(curDetail -> {
                            String key = curDetail.getObjId() + '-' + curDetail.getRoleId();
                            Product product = ProductCache.get(curDetail.getObjId());
                            if (!KiteStringUtils.equals(CoreDataProduct.PRD_0004_101, product.getProdFuncType())) {
                                return;
                            }

                            if (offerDetailMap.containsKey(key)) {
                                // 处理主套餐和促销同时配置一个成员产品的数据，优先取主套餐，不取促销的问题
                                OfferDetail detail = offerDetailMap.get(key);
                                String offerIdMap = detail.getOfferId();
                                Offer offer1 = OfferCache.get(offerIdMap);
                                String curofferId = curDetail.getOfferId();
                                Offer offer2 = OfferCache.get(curofferId);
                                if (CoreDataOffer.OFF_0005_13.equals(offer1.getOfferType()) &&
                                    (CoreDataOffer.OFF_0005_11.equals(offer2.getOfferType()))) {
                                    offerDetailMap.put(key, curDetail);
                                }
                                OfferDetail tmpdetail = offerDetailMap.get(key);

                                // 计算成员最小值(比较两个成员最小值，取值最大的)
                                tmpdetail.setMinNum(
                                    countOfferDetailMaxNum(tmpdetail.getMinNum(), curDetail.getMinNum()));
                                // 计算成员最大值(比较两个成员最大值，取值最大的)
                                tmpdetail.setMaxNum(
                                    countOfferDetailMaxNum(tmpdetail.getMaxNum(), curDetail.getMaxNum()));
                            }
                            else {
                                offerDetailMap.put(key, curDetail);
                            }

                        });
                        return details;
                    });

            });

            if (!KiteMapUtils.isEmpty(offerDetailMap)) {
                offerDetails.clear();
                // Map转换List
                for (OfferDetail offerDetail : offerDetailMap.values()) {
                    offerDetails.add(offerDetail);
                }
            }
        }

        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(offerDetails, OfferDetailDTO.class));
    }

    /**
     * Description: <br>
     * 计算成员角色数量最大值
     *
     * @taskId <br>
     * @param sourceNum
     * @param targetNum
     * @return <br>
     */
    private String countOfferDetailMaxNum(String sourceNum, String targetNum) {
        int num = 1;

        int a = Optional.ofNullable(sourceNum).map(s -> Integer.parseInt(sourceNum)).orElse(0);
        int b = Optional.ofNullable(targetNum).map(s -> Integer.parseInt(targetNum)).orElse(0);
        num = Math.max(a, b);

        return String.valueOf(num);
    }

    @Override
    public DataResult<List<SpeedTypeVO>> listSpeedBroadbandOffer(String offerId, String labelId) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(labelId, "labelId");
        ProdAttrValueRestrictInfoMapper mapper = SpringUtil.getBean(ProdAttrValueRestrictInfoMapper.class);
        Offer offer = OfferCache.get(offerId);

        List<SpeedTypeVO> speedTypeVOList = new ArrayList<SpeedTypeVO>();

        List<OfferRelInfo> offerRelInfos = offer.listAllOfferRels();
        offerRelInfos.forEach(offerRelInfo -> {
            Offer offerZ = OfferCache.get(offerRelInfo.getzOfferId());
            List<ObjectLabelRel> labelRel = offerZ.listOfferLabels(); // 取约束
            labelRel.forEach(objectLabelRel -> {
                if (KeyConsts.LABEL_ID_23.equals(objectLabelRel.getLabelId())) {
                    SpeedTypeVO speedTypeVO = new SpeedTypeVO();
                    Offer offerLabelList = OfferCache.get(objectLabelRel.getOfferId());
                    speedTypeVO.setOfferId(offerLabelList.getOfferId());
                    speedTypeVO.setOfferName(offerLabelList.getOfferName());
                    speedTypeVO.setOfferType(offerLabelList.getOfferType());
                    speedTypeVO.setType(KeyConsts.ADDITIONAL_PRODUCT_TYPE);
                    List<ProdAttrValueRestrictInfo> listValueAttrRestrictList = mapper.getProdAttrValueRestrictByDetail(
                        offerRelInfo.getzOfferId(), IKeyValues.PRODUCT_CLASSIFICATION_ACCESS,
                        IKeyValues.STATUS_CD_1000);
                    List<Map<String, Object>> speedDesc = new ArrayList<>();
                    listValueAttrRestrictList.stream().forEach(prodAttrValueRestrictInfo -> {
                        Map<String, Object> attr = new HashMap<>();
                        AttrValue attrValue = AttrValueCache.getAttrValue(KeyConsts.ATTR_ID_100018,
                            prodAttrValueRestrictInfo.getAttrValue());
                        attr.put("attrValue", prodAttrValueRestrictInfo.getAttrValue());
                        attr.put("attrValueDesc", attrValue.getAttrValueName());
                        attr.put("actionType", "F");
                        speedDesc.add(attr);
                    });
                    List<String> valueDesc = listValueAttrRestrictList.stream()
                        .map(ProdAttrValueRestrictInfo::getAttrValueDesc).collect(Collectors.toList());
                    speedTypeVO.setOfferNameDesc(I18nUtil.getMessage("BSS_KITE_ATTR_43052") + valueDesc);
                    speedTypeVO.setSpeedDesc(speedDesc);
                    speedTypeVOList.add(speedTypeVO);
                }
            });
        });
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(speedTypeVOList, SpeedTypeVO.class));
    }

    @Override
    public DataResult<List<OfferRoleExtDTO>> listMainOfferOfPromotionOffer(String offerId, String mainOfferId) {
        List<String> offerLabels = OfferLabelCache.get(offerId).stream().map(ObjectLabelRel::getLabelId)
            .collect(Collectors.toList());
        if (KiteListUtils.isNotEmpty(offerLabels)) {
            // 11015611 标签的销售品不能查询offer_rel的关系，只能作为普通的促销受理;界面不需要弹出右边主套餐选择的抽屉
            if (offerLabels.contains(LabelConsts.SHARED_FUSION_PROMOTION_OFFER_LABEL_ID)) {
                return ErrorConsts.SUCCESS.getResult(new ArrayList<>());
            }
        }
        return ErrorConsts.SUCCESS.getResult(offerRelMapper.listMainOfferOfPromotionOffer(offerId, mainOfferId));
    }

    @Override
    public DataResult<List<OfferRelDTO>> listAOfferRelsByz(String offerId, String relType) {
        KiteObjectUtils.checkParamIsEmpty(offerId, "offerId");
        KiteObjectUtils.checkParamIsEmpty(relType, "relType");
        List<OfferRelInfo> offerRelInfos = offerRelMapper.listAOfferRelsByOfferId(offerId, relType);
        return ErrorConsts.SUCCESS.getResult(KiteBeanUtils.copyPropsForList(offerRelInfos, OfferRelDTO.class));
    }


    public DataResult<List<OfferRoleExtDTO>> listBaseOfferFromProdRel(String baseOfferId) {
        Offer baseOffer = OfferCache.get(baseOfferId);
        List<Product> accessProds = baseOffer.listAccessProducts();
        if (Objects.isNull(accessProds)) {
            ErrorConsts.OFFER_PROD_REL_NOT_FOUND.throwOut(baseOffer.getOfferName());
        }

        if (accessProds.size() > 1 || accessProds.size() == 0) {
            ErrorConsts.BASE_OFFER_DETAIL_SELECT_MULTI.throwOut(baseOffer.getOfferName());
        }
        Product product = accessProds.get(0);

        List<ProdRelInfo> allProdRelInfos = new ArrayList<ProdRelInfo>();
        allProdRelInfos.addAll(ProdRelCache.getByRelType(product.getProdId(), RelType.PROD_REL_TYPE_100098.getCode()));
        allProdRelInfos.addAll(ProdRelCache.getByRelType(product.getProdId(), RelType.PROD_REL_TYPE_100099.getCode()));

        // 只能通过A端 作为1 托 2的方式来安装；
        Iterator<ProdRelInfo> items = allProdRelInfos.iterator();
        while (items.hasNext()) {
            ProdRelInfo prodRelInfo = items.next();
            if (!(KiteStringUtils.equals(product.getProdId(), prodRelInfo.getaProdId()))) {
                items.remove();
            }
        }

        return ErrorConsts.SUCCESS.getResult(CopyToDtoUtil.transOfferRoleDtoFromProductList(allProdRelInfos));
    }

    @Override
    public DataResult<List<OfferDTO>> listOffer(String offerName) throws Exception {
        Map<String, Object> uniBssBody = new HashMap<>();
        Map<String, Object> salegoodslistincategroyReq = new HashMap<>();
        salegoodslistincategroyReq.put("CATEGROY_CODE", null);
        salegoodslistincategroyReq.put("GOODS_NAME", offerName);
        salegoodslistincategroyReq.put("ISSALE_GOODS_TYPE", "true");
        salegoodslistincategroyReq.put("TOUCH_POINT", "24");
        uniBssBody.put("SALEGOODSLISTINCATEGROY_REQ", salegoodslistincategroyReq);
        Map<String, Object> param = LocalTokenUtil.getParamMap(uniBssBody);
        param.put("OP_CODE", "json_jike_orderCenter_saleGoodsListInCategroy");
        InfServiceHelper.adaptGray(param, salegoodslistincategroyReq);
        String goodsJsonStr;
        if (CallClientUtils.callByHttp()) {
            goodsJsonStr = HttpsCallClient.postStringWithObject(LocalCallClientEnum.INF_COMMON_URL.getCenterCode(),
                LocalCallClientEnum.INF_COMMON_URL.getServiceCode(), param, LocalTokenUtil.getHeaderMap());
        }
        else {
            InfExchangeService infExchangeService = SpringUtil.getBean("infExchangeService");
            goodsJsonStr = infExchangeService.exchange(new JSONObject(param));
        }

        Map<String, Object> goodsMap = JSON.parseObject(goodsJsonStr, Map.class);
        Map<String, Object> resultBodyMap = (Map<String, Object>) goodsMap.get("UNI_BSS_BODY");
        Map<String, String> goodsListInCategroyRsp = (Map<String, String>) resultBodyMap.get("SALEGOODSLISTINCATEGROY_RSP");

        List<OfferDTO> list = new ArrayList<>();
        String goodsInfoListStr = KiteMapUtils.getString(goodsListInCategroyRsp, "data");
        if (StringUtils.isEmpty(goodsInfoListStr)) {
            return ErrorConsts.SUCCESS.getResult(list);
        }

        List<Map> goodsList = JsonUtil.json2List(goodsInfoListStr);
        if (CollectionUtils.isNotEmpty(goodsList)) {
            for (Map goodsInfo : goodsList) {
                if (KiteMapUtils.isNotEmpty(goodsInfo)) {
                    Offer offer = GoodsInfoTransfer.convertOffer(goodsInfo);
                    OfferDTO offerDTO = new OfferDTO();
                    KiteBeanUtils.copyProperties(offer, offerDTO);
                    list.add(offerDTO);
                }
            }
        }

        return ErrorConsts.SUCCESS.getResult(list);
    }

    /**
     * 查询销售品
     * <li>如果按销售品名称模糊查询，直接查库
     * <li>如果不带销售品名称条件的，条件都是比较固定的，从缓存获取
     * @param params
     * @param pageIndex
     * @param pageSize
     * @return
     */
    private List<OfferDTO> fetchOfferListOptimization(Map<String, Object> params, int pageIndex, int pageSize) {
        params = Optional.ofNullable(params).orElse(new HashMap<>());
        if (params.containsKey("offerName") || GeneralSwitchUtils.isSwitchClosed(SwitchConsts.QUERY_OFFER_CACHE)) {
            return listOffers(params, pageIndex, pageSize);
        }

        params.remove("content");
        // TreeMap按key排序
        Map<String, Object> treeMap = new TreeMap<>(params);
        String key = JSON.toJSONString(treeMap);
        List<OfferDTO> offers = QueryOfferCache.get(key);
        if (Objects.nonNull(offers)) {
            return offers;
        }

        offers = listOffers(params, pageIndex, pageSize);
        QueryOfferCache.put(key, offers);

        return offers;
    }

    /**
     * 按条件从数据库查询销售品
     * @param params
     * @param pageIndex
     * @param pageSize
     * @return
     */
    private List<OfferDTO> listOffers(Map<String, Object> params, int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize, false);
        OfferMapper offerMapper = SpringUtil.getBean(OfferMapper.class);
        List<OfferDTO> offers = offerMapper.fetchOfferListOptimization(params);
        offers = Optional.ofNullable(offers).orElse(new ArrayList<>());

        return offers;
    }

    /**
     * 去重，以基础销售品的可选包为主
     * @param mainOfferList
     * @param baseOfferList
     */
    public void distinctOfferByOfferId(List<OfferDTO> mainOfferList, List<OfferDTO> baseOfferList) {
        if (GeneralSwitchUtils.isSwitchClosed("DISTINCT_OFFER_BY_OFFER_ID")) {
            return;
        }

        if (KiteListUtils.isEmpty(mainOfferList) || KiteListUtils.isEmpty(baseOfferList)) {
            return;
        }
        Iterator<OfferDTO> iter = mainOfferList.iterator();
        while (iter.hasNext()) {
            OfferDTO mainOffer = iter.next();
            for (OfferDTO baseOffer : baseOfferList) {
                if (KiteStringUtils.isEqual(baseOffer.getOfferId(), mainOffer.getOfferId())) {
                    iter.remove();
                    break;
                }
            }
        }
    }
}
